/**
 * 添加车辆
 */
layui.use(['form', 'admin', 'HttpRequest'], function () {
    var form = layui.form;
    var admin = layui.admin;
    var HttpRequest = layui.HttpRequest;
    var $ = layui.$;
    var util = layui.util;


    // 设备品牌下拉框回显
    layui.use(['form', 'upload', 'layer'],function(){
        var form = layui.form;
        $.ajax({
            url: Feng.ctxPath + '/device/brandList',
            dataType: 'json',
            type: 'get',
            success: function (data) {
                //使用循环遍历，给下拉列表赋值
                $.each(data.data, function (index, value) {
                    var option = new Option(value.name,value.devcieBrandId);
                    $('#deviceBrand').append(option);// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        })
    });

    // 设备类型下拉框回显
    layui.use(['form', 'upload', 'layer'],function(){
        var form = layui.form;
        $.ajax({
            url: Feng.ctxPath + '/dict/getDictListPage',
            data:{page:"1",limit:"10",dictTypeCode:"deviceType"},
            dataType: 'json',
            type: 'get',
            success: function (data) {
                //使用循环遍历，给下拉列表赋值
                $.each(data.data.rows, function (index, value) {
                    var option = new Option(value.dictName,value.dictCode);
                    $('#deviceType').append(option);// 下拉菜单里添加元素
                });
                layui.form.render("select");//重新渲染 固定写法
            }
        })
    });






    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var request = new HttpRequest(Feng.ctxPath + "/device/add", 'post', function (data) {
            admin.closeThisDialog();
            Feng.success("添加成功！");
            admin.putTempData('formOk', true);
            parent.location.reload();
        }, function (data) {
            admin.closeThisDialog();
            Feng.error("添加失败！" + data.message);
        });
        request.set(data.field);
        request.start(true);
    });

});